package com.hdoit.ares.logical.official.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.official.dao.IArticalPraiseDao;
import com.hdoit.ares.logical.official.dao.IPraiseAndGlanceDao;
import com.hdoit.ares.logical.official.model.ArticalPraise;
import com.hdoit.ares.logical.official.model.PraiseAndGlance;
import com.hdoit.ares.logical.official.service.IArticalPraiseService;
import com.tennetcn.common.dao.base.impl.SuperService;
import com.tennetcn.common.message.DaoBaseException;
import com.tennetcn.common.utils.CommonUtils;
import com.tennetcn.common.utils.DateUtils;
/**
 * @author      yujinhui
 * @email       
 * @createtime  2018年03月10日 15:39:13
 * @comment
 */
@Component
public class ArticalPraiseServiceImpl extends SuperService<ArticalPraise> implements IArticalPraiseService{
	private IArticalPraiseDao articalPraiseDao;
	private IPraiseAndGlanceDao praiseAndGlanceDao;
	
	public IArticalPraiseDao getArticalPraiseDao() {
		return articalPraiseDao;
	}
	@Resource
	public void setArticalPraiseDao(IArticalPraiseDao articalPraiseDao) {
		this.articalPraiseDao = articalPraiseDao;
	}
	
	public IPraiseAndGlanceDao getPraiseAndGlanceDao() {
		return praiseAndGlanceDao;
	}
	@Resource
	public void setPraiseAndGlanceDao(IPraiseAndGlanceDao praiseAndGlanceDao) {
		this.praiseAndGlanceDao = praiseAndGlanceDao;
	}
	
	@Override
	public ArticalPraise queryModel(String receiveId, String type,String customerId) {
		return articalPraiseDao.queryModel(receiveId,type,customerId);
	}
	@Override
	public String toThumb(String id, String type, String customerId) {
		//判断是否点过赞
		ArticalPraise articalPraise = this.queryModel(id,type,customerId);
		if(articalPraise == null){
			articalPraise = new ArticalPraise();
			articalPraise.setId(CommonUtils.getKeyId());
			articalPraise.setCreateTime(DateUtils.getCurrent());
			articalPraise.setType(type);
			articalPraise.setReceiveId(id);
			articalPraise.setCustomerId(customerId);
			if(this.addModel(articalPraise)){
				PraiseAndGlance praiseAndGlance = praiseAndGlanceDao.queryModel(id,type);
				System.err.println(praiseAndGlance == null);
				praiseAndGlance.setPraiseCount(praiseAndGlance.getPraiseCount() + 1);
				try {
					praiseAndGlanceDao.updateModel(praiseAndGlance);
				} catch (DaoBaseException e) {
					e.printStackTrace();
				}
			}
			return String.valueOf(false);
		}
		return  String.valueOf(true);	

	}
	
	

}